#include "TriangleMesh.h"

const HashedString TriangleMesh::type("TriangleMesh");

TriangleMesh::TriangleMesh( float *verts, int numTriangle )
{
	Pointer<int> indices = new int[numTriangle * 3];
	for (int i = 0; i < numTriangle * 3; ++i)
		indices[i] = i;

	float *temp = verts;
	btTriangleMesh* triangles = new btTriangleMesh();
	for (int i = 0; i < numTriangle; ++i)
	{
		float *a = temp;
		temp += 3;
		float *b = temp;
		temp += 3;
		float *c = temp;
		temp += 3;

		btVector3 A(a[0], a[1], a[2]);
		btVector3 B(b[0], b[1], b[2]);
		btVector3 C(c[0], c[1], c[2]);

		triangles->addTriangle(A, B, C);
	}
	
	btTriangleIndexVertexArray *otherTris = new btTriangleIndexVertexArray(numTriangle, (int*)indices.getPointer(), 4, numTriangle*3, verts, 16);


	m_bulletShape = new btBvhTriangleMeshShape(triangles, true, true);
	//m_bulletShape = new btStaticPlaneShape(btVector3(0,1,0),1);
	//m_localOffset = btTransform(btQuaternion(0,0,0,1), btVector3(0,100,0));
}

const HashedString& TriangleMesh::Type() const
{
	return type;
}

std::string TriangleMesh::ToString() const
{
	return "";
}